<?php function renderingReqPage($viewHtml,$appendHeadStr,&$errorStr){$doc=new DOMDocument();if(false===@$doc->loadHTML(preg_replace('#<meta\s+(?:[^>]+\s+)*charset="([\w-]+)"(?>[^>]*)>#i','<meta http-equiv="Content-Type" content="text/html;charset=${1}">',$viewHtml,1))){return['html'=>'Failure load the HTML content.'];}$regionClsStr='zmsun_a_module_region';$xpath=new DOMXPath($doc);if(!($regions=$xpath->query("//*[contains(@class, '$regionClsStr')]"))||!iterator_count($regions)){return['html'=>'No content can be edited.'];}$maskStr1=<<<S
<div class="zmsun_a_module_layer">
	<div class="zmsun_a_module_mask"></div>
	<div class="zmsun_a_module_opt">
		<a class="zmsun_a_ds-bar-add"><span>&#160;</span></a>
	</div>
</div>
S;
$maskStr2=<<<S
<div class="zmsun_a_module_layer">
	<div class="zmsun_a_module_mask"></div>
	<div class="zmsun_a_module_opt">
		<a class="zmsun_a_ds_bar_edit"><span>&#160;</span></a>
		<a class="zmsun_a_ds-bar-moveup"><span>&#160;</span></a>
		<a class="zmsun_a_ds-bar-movedown"><span>&#160;</span></a>
		<a class="zmsun_a_ds-bar-del"><span>&#160;</span></a>
		<a class="zmsun_a_ds-bar-add"><span>&#160;</span></a>
	</div>
</div>
S;
foreach($regions as$region){$classStr=$region->attributes->getNamedItem("class")->textContent;if(false!==strpos($classStr,'zmsun_a_module_region_empty')){$emptyFragment=$doc->createDocumentFragment();$emptyFragment->appendXML($maskStr1);$region->appendChild($emptyFragment);}else{$sFragment=$doc->createDocumentFragment();$sFragment->appendXML($maskStr2);$region->appendChild($sFragment);}}if(($header=$doc->getElementById('header'))&&$header->hasChildNodes()){$frag=$doc->createDocumentFragment();$frag->appendXML('<div class="zmsun_a_header_sep_tip">以上为页头区域</div>');$header->appendChild($frag);}if(($footer=$doc->getElementById("footer"))&&$footer->hasChildNodes()){$frag=$doc->createDocumentFragment();$frag->appendXML('<div class="zmsun_a_footer_sep_tip">以下为页尾区域</div>');$footer->insertBefore($frag,$footer->firstChild);}if($scripts=$xpath->query("//*[translate(name(), 'SCRIPT', 'script') = 'script']")){foreach($scripts as$script){$script->parentNode->removeChild($script);}}if(($head=$doc->getElementsByTagName('head'))&&$head->length){$frag=$doc->createDocumentFragment();$frag->appendXML($appendHeadStr);$head->item(0)->appendChild($frag);}return['html'=>$doc->saveHTML(),];}$errorStr="";if(empty($_GET['page'])){$errorStr='请求编辑的页面未找到-01';}else{if(!$pcId=strval(Zmsun\System\System::userConfig()->template)){$errorStr='站点未应用PC模板-01';}else{$template=new Zmsun\System\Template\Template(Zmsun\System\System::templateDir().$pcId);$routeMgr=new Zmsun\Router\TemplateRouteManager($this->getServiceManager(),$template->pcPart());if(!file_exists($template->configFile())){$errorStr='站点未应用PC模板-02';}elseif(false===$reqPageUrl=$routeMgr->getUrlByFile($_GET['page'])){$errorStr='请求编辑的页面未找到-02';}}}if($errorStr){exit('<!DOCTYPE html><html lang="zh"><head><meta charset="utf-8"></head><body>'.$errorStr.'</body></html>');}$templatePart=$template->pcPart();$pageBaseDir=$templatePart->masterPageDir();$reqJsonFile=$_GET['page'];if($temData=json_decode(@file_get_contents($pageBaseDir.$reqJsonFile))){if($temData->type!='module'){exit('<!DOCTYPE html><html lang="zh"><head><meta charset="utf-8"></head><body>不可编辑非模块页</body></html>');}}if($reqPageUrl!=='')$_SERVER['REQUEST_URI']=$reqPageUrl;$this->getServiceManager()->setService('CopenManager',new Zmsun\Copen\CopenManager($this->serviceManager,$templatePart));$view=new Zmsun\View\TemplateView($this->getServiceManager(),$templatePart);if(!$view->render($reqJsonFile,true)){exit('<!DOCTYPE html><html lang="zh"><head><meta charset="utf-8"></head><body>'.$view->errorInfo().'</body></html>');}$baseUrl=$this->assetsUri();$appendHeadStr='<link rel="stylesheet" type="text/css" href="'.$baseUrl.'/css/default.css"/>';if(false===$reqPageData=renderingReqPage($view->getContent(),$appendHeadStr,$errorStr)){exit('<!DOCTYPE html><html lang="zh"><head><meta charset="utf-8"></head><body>'.$errorStr.'</body></html>');}echo$reqPageData['html'];?>